using GameFramework.Battle.Core;
using Gameplay.PVE.Config;
using Gameplay.PVE.Entity;
using Gameplay.PVE.Utils;
using UnityEngine;

namespace Gameplay.PVE.Skill
{
    //满足条件后自动释放的技能
    public class SkillAuto : SkillBase
    {
        protected override void Storage()
        {
            base.Storage();
            if (!string.IsNullOrEmpty(config.storage_name))
            {
                unit.Play(config.storage_name);
            }
            unit.Data.SetTargetForward(targetPosition - unit.Data.position);
            if (config.id == 1023000)
            {
                unit.Transmit(ETransmitType.ShowOneGhostShadow);
            }
        }

        protected override void Cast()
        {
            base.Cast();
            if (!string.IsNullOrEmpty(config.action_name))
            {
                unit.Play(config.action_name);
            }
            unit.Data.SetIsInSkill(true);
        }

        protected override void StartRecover()
        {
            base.StartRecover();
            if (!string.IsNullOrEmpty(config.recover_name))
            {
                unit.Play(config.recover_name);
            }
            else if (!string.IsNullOrEmpty(config.action_name))
            {
                unit.Play("Idle");
            }
        }

        protected override void Recover()
        {
            OnStop();
        }

        protected override void OnStop()
        {
            unit.Transmit(ETransmitType.AttackEnd);
            unit.Transmit(ETransmitType.OnAutoSkillEnd);
            unit.Data.attackState = 0;
            unit.Data.SetIsInSkill(false);
            base.OnStop();
        }

        protected override void CastEvent()
        {
            if (config.summon_id != 0) //召唤类技能
            {
                UpdateSummonSkill();
            }
            else
            {
                base.CastEvent();
            }
        }

        protected override void OnForceStop()
        {
            base.OnForceStop();
            unit.Play("SkillForceStop");
        }


        
        protected override bool CheckIsCanSkill()
        {
            return true;
        }
    }
}